<template>
  <a-row :gutter="5">
    <a-col :span="4">
      <FlowTree ref="FlowTree" @selected="getTreeData"></FlowTree>
    </a-col>
    <a-col :span="20">
      <a-card style="position: relative">
        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns"
          :pagination="false"
          :dataSource="dataSource"
          :loading="loading"
          :scroll="{ x: 200, y: 730 }">
          <template slot="actionName">
            <a-button size="small" @click="handle_Add('节点配置-新增')" type="primary" icon="plus">新增</a-button>
          </template>
          <template slot="roleNames" slot-scope="text, record">
            <span>{{record.roleNames.toString()}}</span>
          </template>
          <template slot="action" slot-scope="text, record,index">
            <a @click="handleEdit(record,'节点配置-编辑')">编辑</a>
            <a-divider type="vertical"/>
            <a-popconfirm placement="leftTop" title="是否删除？" @confirm="handleDel(record,index)">
              <a-icon slot="icon" type="question-circle-o" style="color: red"/>
              <a>删除</a>
            </a-popconfirm>
          </template>
        </a-table>
        <CheckAndEditModel ref="modalForm" @ok="modalFormOk"></CheckAndEditModel>
      </a-card>
    </a-col>
  </a-row>
</template>
<script>
  // 表头
  import FlowTree from './FlowTree'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import columns from "./indexColumns";
  import {httpAction, getAction} from '@/api/manage'
  import CheckAndEditModel from './CheckAndEditModel'

  export default {
    name: '流程配置审批表',
    mixins: [JeecgListMixin],
    components: {
      FlowTree,
      CheckAndEditModel
    },
    data() {
      return {
        queryParam: {
          modelCode: '',
        },
        columns: columns(this),
        url: {
          list: '/process/list',
          del: '/process/del'
        },
      }
    },
    computed: {},
    methods: {
      handleDel(record, index) {
        httpAction(this.url.del, {
          id: record.id,
          modelCode: record.modelCode
        }, 'post').then((res) => {
          if (res.success) {
            this.$message.success(res.message);
            this.$refs.FlowTree.loadData()
            this.loadData();
          } else {
            this.$message.error(res.message);
          }
        })
      },
      getTreeData(data) {
        if(data.constructor === Object){
          this.queryParam.modelCode = data.modelCode
        }else{
          this.queryParam.modelCode = data[0]
        }
        this.loadData();
      },
      handle_Add: function (name) {
        this.$refs.modalForm.add(this.queryParam.modelCode);
        this.$refs.modalForm.title = name;
      },
    }
  }
</script>
<style lang="less" scoped>
  .ant-row {
    height: 100%;

    .ant-col {
      height: 100%;

      .ant-card {
        height: 100%;

        /deep/ .ant-card-body {
          padding: 15px;
        }
      }
    }

  }
</style>